export const initCards = (options={})=>{
    let cardList = ['A','2','3','4','5','6','7','8','9','10','J','Q','K']
    const cardValue = [14,15,3,4,5,6,7,8,9,10,11,12,13]
    cardList = cardList.map((item,index)=>{
        return {
            label:item,
            value:cardValue[index],
        }
    })
    // Spade 黑桃 ,
    // Heart 红桃 
    // Diamond 方片 
    // club 草花 
    const cardType = ['heart','diamond','club','spade']
    const jokers = [{type:'joker',label:'Joker',value:17},{type:'small-joker',label:'Joker',value:16}]
    const cards = cardList.reduce((pre,cur)=>{
        cardType.forEach((item,index)=>{
            pre.push({
                type:item,
                label:cur.label,
                value:cur.value,
            })
        })
        return pre
    },[])
    return cards.concat(jokers)
}
export const getCardsValue = (cards) =>{
    return cards.map(item=>item.value)
}
export const isSingle = (cards) =>{
    return cards.length === 1
}
export const isPair = (cards) =>{
    if(cards.length !== 2) return false
    return getCardsValue(cards)[0] === getCardsValue(cards)[1]
}
export const isStraight = (cards) =>{
    if(cards.length < 5) return false
    const cardsValue = getCardsValue(cards)
    const maxValue = Math.max(...cardsValue)
    const minValue = Math.min(...cardsValue)
    const cardsLength = cardsValue.length
    const cardsRange = maxValue - minValue
    if(cardsRange === cardsLength - 1) return true
}
export const isThreeWithOne = (cards) =>{
    if(cards.length !== 4) return false
    const cardsValue = getCardsValue(cards)
    const cardsValueSet = new Set(cardsValue)
    if(cardsValueSet.size === 2) return true
}
export const isThreeWithTwo = (cards) =>{
    if(cards.length !== 5) return false
    const cardsValue = getCardsValue(cards)
    const cardsValueSet = new Set(cardsValue)
    if(cardsValueSet.size === 2) return true
}

export const isStraightPair = (cards) =>{
    if(cards.length !== 6) return false
    const cardsValue = getCardsValue(cards)
    const cardsValueSet = new Set(cardsValue)
    if(cardsValueSet.size === 3) return true
}

export const isBomb = (cards) =>{
    if(cards.length !== 4) return false
    const cardsValue = getCardsValue(cards)
    const cardsValueSet = new Set(cardsValue)
    if(cardsValueSet.size === 1) return true
}


export const isRocket = (cards) =>{
    if(cards.length !== 2) return false
    const cardsValue = getCardsValue(cards)
    return cardsValue.includes(17) && cardsValue.includes(16)
}
// 赖子
export const isStraightBomb = (cards) =>{
    if(cards.length !== 5) return false
    const cardsValue = getCardsValue(cards)
    const cardsValueSet = new Set(cardsValue)
    if(cardsValueSet.size === 1) return true
}
// 连对
export const isConsecutivePairs = (cards)=> {
    if (cards.length % 2 !== 0 || cards.length < 6) return false;
    const values = cards.map(getCardValue).sort((a, b) => a - b);
    for (let i = 0; i < values.length; i += 2) {
        if (values[i] !== values[i + 1]) return false;
    }
    return isStraight(values.filter((v, i) => i % 2 === 0));
}
// 飞机
